/*jslint browser: true, devel: true, bitwise: true, white: true, plusplus: true, nomen:true */
/*global $:true, define:true */

/**
 * @module UI
 */

define(['WID/UI/Widget','WID/UI/Panel','WID/UI/Button','WID/UI/Label'],
function(Widget,Panel,Button,Label) {
"use strict";

/** 
 * Okno, może być zwykłe lub w postaci predefinioweanej(alert,popup,promot,info itp).
 * @class Window
 * @constructor
 */
function Window(props) {
	props = props||{};
	props.bgType = 'glass';
	Panel.call(this,props);
	
	this.setSize(props.w||'308',props.h||'338');
	
	var context = this, element = $(this.ntv);
	element.addClass('nlWindow');

	element.draggable({disabled:!props.draggable});
	element.resizable({disabled:!props.resizable,minWidth:200,minHeight:100});
	
	if (!props.nobar) {
		this.Bar = new Panel();
		this.Bar.ntv.setAttribute('nlwbar','');
		this.Caption = new Label({parent:this.Bar,text:props.caption||'Window', css:{fontWeight:'bold'}});
		
		this.btnClose = new Button({caption:'X',parent:this.Bar,events:{click:function(){
			context.close();
		}}});
		this.btnClose.ntv.setAttribute('nlwclose','');
		Panel.prototype.addChild.call(this,this.Bar);
	}

	this.Content = new Panel({type:props.layout,childs:props.content});
	this.Content.ntv.setAttribute('nlwcontent','');
	Panel.prototype.addChild.call(this,this.Content);
	
} var extend = Object.create(Panel.prototype); extend.constructor = Window;

Window.NORMAL = 0;
Window.POPUP = 1;
Window.ALERT = 2;
Window.PROMOT = 3;
Window.INFO = 4;

extend.close = function() {
	this.Parent.removeChild(this);
};

extend.addChild = function(child) {
	this.Content.addChild(child);
};

extend.removeChild = function(child) {
	this.Content.addChild(child);
};

Widget.defineProps(extend,{
	resizable: {
		get: function() {
			return $(this.ntv).resizable( "option", "disabled" );
		},
		set: function(enable) {
			$(this.ntv).resizable((enable)?'enable':'disable');
		}
	},
	
	draggable: {
		get: function() {
			return $(this.ntv).draggable( "option", "disabled" );
		},
		set: function(enable) {
			$(this.ntv).draggable((enable)?'enable':'disable');
		}
	}
});

Window.prototype = extend;
return Window;
});
